$(function () {
    var serviceData = [];
    var searchData = [];
    var serviceTable = null;
    var isSearchAll = true;
    serviceData = [
        {
            id: 'ylz.nlsc.getPersonInfo',
            serviceNumber: 'ylz.nlsc.getPersonInfo',
            serviceName: '获取人员的生存状态',
            processType: 'WebService处理器',
            serviceMark: '',
            builder: '天河区-user',
            buildTime: '20180625'
        }, {
            id: 'ylz.nlsc.getDeathInfo',
            serviceNumber: 'ylz.nlsc.getDeathInfo',
            serviceName: '获取人员的户籍信息',
            processType: 'WebService处理器',
            serviceMark: '',
            builder: '天河区-user',
            buildTime: '20180701'
        }, {
            id: 'ylz.nlsc.getInsureInfo',
            serviceNumber: 'ylz.nlsc.getInsureInfo',
            serviceName: '获取人员的联系方式',
            processType: 'WebService处理器',
            serviceMark: '',
            builder: '天河区-user',
            buildTime: '20180702'
        }
    ];
    //layui使用
    layui.use(['form', 'layer','laydate'], function () {
        var form = layui.form,
            layer = layui.layer;
			laydate = layui.laydate;

        //监听提交
        form.on("submit(demo1)",function(data){
            searchData = [];
            var searchLoad = layer.load();
            var submitData = data.field;
            if(submitData.serviceNumber || submitData.serviceName ){
                isSearchAll = false;
            }else{
                isSearchAll = true;
            }
            $.each(serviceData,function(i,item){
                if(submitData.serviceName && submitData.serviceName == item.serviceName){
                    searchData.push(item);
                }
            });
            if(serviceTable != null){
                serviceTable.clear();
                serviceTable.destroy();
            }
            initTable();
            setTimeout(function(){
                layer.close(searchLoad);
            },500);
            return false;
        });
        initTable();
		//数据期别初始化
        laydate.render({
            elem: '#timeFrom',
            format: "yyyyMM",
            value: new Date(),
            type: 'month'
        });
		//数据期别初始化
        laydate.render({
            elem: '#timeTo',
            format: "yyyyMM",
            value: new Date(),
            type: 'month'
        });
    });
    //初始化表格
    function initTable() {
        serviceTable = $("#serviceTable").DataTable({
            searching: false,
            ordering: false,
            lengthChange: false,
            //retrieve: false,
            //国际化
            language: {
                search: "在表格中搜索:",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                }
            },
            columns: [{
                data: 'serviceNumber',
                width: '15%'
            }, {
                data: 'serviceName',
                width: '15%'
            }, {
                data: 'processType',
                width: '10%'
            }, {
                data: 'serviceMark',
                width: '10%'
            }, {
                data: 'builder',
                width: '8%'
            },{
                data: 'buildTime',
                width: '10%'
            }],
            data: isSearchAll ? serviceData : searchData
        });

    }

    //资源输出情况统计
    $(".firstItem").on("click", function () {
        var index = $(this).attr("data-index");
        $(".secondItem-" + index).slideDown().addClass("lay-show").siblings().removeClass("lay-show").hide();
    });
});